﻿using System;
using System.Collections.Generic;
using System.Text;
using DotNet.Common;
using DotNet.Data.Factory;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace DotNet.Data
{
	public class tab_caseClassDal
	{
		IDBHelp db = DBHelp.Create();
		 Hashtable htSyn = Hashtable.Synchronized(new Hashtable());
		StringBuilder strSql = new StringBuilder();

		#region 是否存在该记录
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		/// <param name="ccid">标识列ID</param>
		public bool Exists(int ccid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select count(1) from [tab_caseClass] where ccid=@ccid ");
			htSyn.Add("@ccid", ccid);
			return db.IsExists(strSql.ToString(), htSyn);
		}
		#endregion

		#region 得到该表数据列表
		/// <summary>
		/// 得到该表数据列表
		/// </summary>
		public IList<tab_caseClass> GetModel()
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("Select [caseClassDate],[ccid],[caseClassFID],[caseClassKey],[caseClassDescription],[caseClassName],[caseClassInfo],[caseTitle] FROM [tab_caseClass]");
			 return gettab_caseClassBySql(strSql.ToString());
		}
		#endregion

		#region 根据标识列查询实体
		/// <summary>
		/// 根据标识列查询实体
		/// </summary>
		/// <param name="ccid">标识列ID</param>
		/// <returns></returns>
		public tab_caseClass GetModel(int ccid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("select [caseClassDate],[ccid],[caseClassFID],[caseClassKey],[caseClassDescription],[caseClassName],[caseClassInfo],[caseTitle] FROM [tab_caseClass]");
			strSql.Append(" where ccid=@ccid ");
			htSyn.Add("@ccid", ccid);
			DataTable dt = db.GetDataTable(strSql.ToString(), htSyn);
			tab_caseClass tab_caseclassModel = new tab_caseClass();
			if (dt.Rows.Count > 0)
			{
				tab_caseclassModel.caseClassDate=Convert.ToDateTime(dt.Rows[0]["caseClassDate"]);
				tab_caseclassModel.caseClassFID=Convert.ToInt32(dt.Rows[0]["caseClassFID"]);
				tab_caseclassModel.caseClassKey=dt.Rows[0]["caseClassKey"].ToString();
				tab_caseclassModel.caseClassDescription=dt.Rows[0]["caseClassDescription"].ToString();
				tab_caseclassModel.caseClassName=dt.Rows[0]["caseClassName"].ToString();
				tab_caseclassModel.caseClassInfo=dt.Rows[0]["caseClassInfo"].ToString();
				tab_caseclassModel.caseTitle=dt.Rows[0]["caseTitle"].ToString();
			}
			return tab_caseclassModel;
		}
		#endregion

		#region 修改信息
		/// <summary>
		/// 修改信息
		/// </summary>
		/// <param name="tab_caseClass">实体</param>
		/// <returns></returns>
		public bool Update(tab_caseClass tab_caseclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("update [tab_caseClass] set ");
			strSql.Append("[caseClassDate]=@caseclassdate,");
			strSql.Append("[caseClassFID]=@caseclassfid,");
			strSql.Append("[caseClassKey]=@caseclasskey,");
			strSql.Append("[caseClassDescription]=@caseclassdescription,");
			strSql.Append("[caseClassName]=@caseclassname,");
			strSql.Append("[caseClassInfo]=@caseclassinfo,");
			strSql.Append("[caseTitle]=@casetitle");

			strSql.Append(" where ccid=@ccid ");
			htSyn.Add("@caseclassdate", tab_caseclassModel.caseClassDate);
			htSyn.Add("@ccid", tab_caseclassModel.ccid);
			htSyn.Add("@caseclassfid", tab_caseclassModel.caseClassFID);
			htSyn.Add("@caseclasskey", tab_caseclassModel.caseClassKey);
			htSyn.Add("@caseclassdescription", tab_caseclassModel.caseClassDescription);
			htSyn.Add("@caseclassname", tab_caseclassModel.caseClassName);
			htSyn.Add("@caseclassinfo", tab_caseclassModel.caseClassInfo);
			htSyn.Add("@casetitle", tab_caseclassModel.caseTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 删除信息
		/// <summary>
		/// 删除信息
		/// </summary>
		/// <param name="ccid">标识列ID</param>
		/// <returns></returns>
		public bool Delete(int ccid)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("delete from [tab_caseClass] where ccid=@ccid");
			htSyn.Add("ccid", ccid);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 添加信息
		/// <summary>
		/// 添加信息
		/// </summary>
		/// <param name="tab_caseClass">实体</param>
		/// <returns></returns>
		public bool Insert(tab_caseClass tab_caseclassModel)
		{
			htSyn.Clear();
			strSql.Remove(0, strSql.Length);
			strSql.Append("insert into [tab_caseClass]([caseClassDate],[caseClassFID],[caseClassKey],[caseClassDescription],[caseClassName],[caseClassInfo],[caseTitle]) values (@caseclassdate,@caseclassfid,@caseclasskey,@caseclassdescription,@caseclassname,@caseclassinfo,@casetitle)");
			htSyn.Add("@caseclassdate", tab_caseclassModel.caseClassDate);
			htSyn.Add("@caseclassfid", tab_caseclassModel.caseClassFID);
			htSyn.Add("@caseclasskey", tab_caseclassModel.caseClassKey);
			htSyn.Add("@caseclassdescription", tab_caseclassModel.caseClassDescription);
			htSyn.Add("@caseclassname", tab_caseclassModel.caseClassName);
			htSyn.Add("@caseclassinfo", tab_caseclassModel.caseClassInfo);
			htSyn.Add("@casetitle", tab_caseclassModel.caseTitle);
			if (db.ExecuteNonQuery(strSql.ToString(), htSyn) > 0)
			{
				return true;
			}
			return false;
		}
		#endregion

		#region 根据SQL语句获取集合
		/// <summary>
		///根据SQL语句获取集合
		/// </summary>
		/// <param name="strSql">sql语句</param>
		public IList<tab_caseClass> gettab_caseClassBySql(string strSql)
		{
			IList<tab_caseClass> list = new List<tab_caseClass>();
			DataTable dt = db.GetDataTable(strSql);
			if (dt.Rows.Count > 0)
			{
				foreach (DataRow dr in dt.Rows)
				{
					tab_caseClass tab_caseclassModel = new tab_caseClass();
					tab_caseclassModel.caseClassDate= Convert.ToDateTime(dr["caseClassDate"]);
					tab_caseclassModel.ccid= Convert.ToInt32(dr["ccid"]);
					tab_caseclassModel.caseClassFID= Convert.ToInt32(dr["caseClassFID"]);
					tab_caseclassModel.caseClassKey=dr["caseClassKey"].ToString();
					tab_caseclassModel.caseClassDescription=dr["caseClassDescription"].ToString();
					tab_caseclassModel.caseClassName=dr["caseClassName"].ToString();
					tab_caseclassModel.caseClassInfo=dr["caseClassInfo"].ToString();
					tab_caseclassModel.caseTitle=dr["caseTitle"].ToString();
					list.Add(tab_caseclassModel);
				}
			}
			return list;
		}
		#endregion
	}
}
